from turbogears import expose, redirect, flash, identity
from mnemoply._renewed_lib.crud import RestrictController, TableCol
from mnemoply._renewed_lib.actions import Action, ParamsColumn
from mnemoply._renewed_model.field import AccountFree as model_AccountFree
from mnemoply.mass_actions import MassAction
from mnemoply.controllers import Report
from mnemoply.utils import objs2ids
from mnemoply._renewed_lib.widgets import TextField

class MAPrint(MassAction):
    target_class = model_AccountFree
    name = "account_print"
    title = _("Print")
    read_only = True

    def call(self, objs):
        return Report.generate('AccountPrint',
            ids=objs2ids(objs),
        )

class AccountFreeController(RestrictController):

    class zzz1(Action):
        columns = [ ParamsColumn('fff111', getter =  lambda(row): row.office.title)]
        name = 'first_discont'#FirstDiscont

    class zzz2(Action):
        columns = [ ParamsColumn('sssssss2222222', getter =  lambda(row): 'bbbbbbb', widget = TextField)]
        name = 'create_charge_record_for_short_course_with_my'
                
    actions = [zzz1(),zzz2()]  
    is_addable = True
    model_object = model_AccountFree
    lookup_columns = [
        TableCol(name='office', caption=_('Office')),
        TableCol(name='account', caption=_('Account')),
   ]

    @expose()
    def add_req(self):
        user = identity.current.user
        office = user.office
        for i in range(10):
            model_AccountFree(office=office or 0)
        raise redirect('.')
    
exposed = AccountFreeController()
